

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="Description" content="scikit-learn: machine learning in Python">

  
  <title>sklearn.decomposition.LatentDirichletAllocation &mdash; scikit-learn 0.22 documentation</title>
  
  <link rel="canonical" href="http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html" />

  
  <link rel="shortcut icon" href="../../_static/favicon.ico"/>
  

  <link rel="stylesheet" href="../../_static/css/vendor/bootstrap.min.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/gallery.css" type="text/css" />
  <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
<script src="../../_static/jquery.js"></script> 
</head>
<body>
<nav id="navbar" class="sk-docs-navbar navbar navbar-expand-md navbar-light bg-light py-0">
  <div class="container-fluid sk-docs-container px-0">
      <a class="navbar-brand py-0" href="../../index.html">
        <img
          class="sk-brand-img"
          src="../../_static/scikit-learn-logo-small.png"
          alt="logo"/>
      </a>
    <button
      id="sk-navbar-toggler"
      class="navbar-toggler"
      type="button"
      data-toggle="collapse"
      data-target="#navbarSupportedContent"
      aria-controls="navbarSupportedContent"
      aria-expanded="false"
      aria-label="Toggle navigation"
    >
      <span class="navbar-toggler-icon"></span>
    </button>

    <div class="sk-navbar-collapse collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../../install.html">Install</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../../user_guide.html">User Guide</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../classes.html">API</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link" href="../../auto_examples/index.html">Examples</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../getting_started.html">Getting Started</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../tutorial/index.html">Tutorial</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../glossary.html">Glossary</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../developers/index.html">Development</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../faq.html">FAQ</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../related_projects.html">Related packages</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../roadmap.html">Roadmap</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="../../about.html">About us</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
        </li>
        <li class="nav-item">
          <a class="sk-nav-link nav-link nav-more-item-mobile-items" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
        </li>
        <li class="nav-item dropdown nav-more-item-dropdown">
          <a class="sk-nav-link nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">More</a>
          <div class="dropdown-menu" aria-labelledby="navbarDropdown">
              <a class="sk-nav-dropdown-item dropdown-item" href="../../getting_started.html">Getting Started</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../tutorial/index.html">Tutorial</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../glossary.html">Glossary</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../developers/index.html">Development</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../faq.html">FAQ</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../related_projects.html">Related packages</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../roadmap.html">Roadmap</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="../../about.html">About us</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://github.com/scikit-learn/scikit-learn">GitHub</a>
              <a class="sk-nav-dropdown-item dropdown-item" href="https://scikit-learn.org/dev/versions.html">Other Versions</a>
          </div>
        </li>
      </ul>
      <div id="searchbox" role="search">
          <div class="searchformwrapper">
          <form class="search" action="../../search.html" method="get">
            <input class="sk-search-text-input" type="text" name="q" aria-labelledby="searchlabel" />
            <input class="sk-search-text-btn" type="submit" value="Go" />
          </form>
          </div>
      </div>
    </div>
  </div>
</nav>
<div class="d-flex" id="sk-doc-wrapper">
    <input type="checkbox" name="sk-toggle-checkbox" id="sk-toggle-checkbox">
    <label id="sk-sidemenu-toggle" class="sk-btn-toggle-toc btn sk-btn-primary" for="sk-toggle-checkbox">Toggle Menu</label>
    <div id="sk-sidebar-wrapper" class="border-right">
      <div class="sk-sidebar-toc-wrapper">
        <div class="sk-sidebar-toc-logo">
          <a href="../../index.html">
            <img
              class="sk-brand-img"
              src="../../_static/scikit-learn-logo-small.png"
              alt="logo"/>
          </a>
        </div>
        <div class="btn-group w-100 mb-2" role="group" aria-label="rellinks">
            <a href="sklearn.decomposition.KernelPCA.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="sklearn.decomposition.KernelPCA">Prev</a><a href="../classes.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="API Reference">Up</a>
            <a href="sklearn.decomposition.MiniBatchDictionaryLearning.html" role="button" class="btn sk-btn-rellink py-1" sk-rellink-tooltip="sklearn.decomposition.MiniBatchDictionaryLearning">Next</a>
        </div>
        <div class="alert alert-danger p-1 mb-2" role="alert">
          <p class="text-center mb-0">
          <strong>scikit-learn 0.22</strong><br/>
          <a href="http://scikit-learn.org/dev/versions.html">Other versions</a>
          </p>
        </div>
        <div class="alert alert-warning p-1 mb-2" role="alert">
          <p class="text-center mb-0">
            Please <a class="font-weight-bold" href="../../about.html#citing-scikit-learn"><string>cite us</string></a> if you use the software.
          </p>
        </div>
          <div class="sk-sidebar-toc">
            <ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sklearn.decomposition</span></code>.LatentDirichletAllocation</a><ul>
<li><a class="reference internal" href="#examples-using-sklearn-decomposition-latentdirichletallocation">Examples using <code class="docutils literal notranslate"><span class="pre">sklearn.decomposition.LatentDirichletAllocation</span></code></a></li>
</ul>
</li>
</ul>

          </div>
      </div>
    </div>
    <div id="sk-page-content-wrapper">
      <div class="sk-page-content container-fluid body px-md-3" role="main">
        
  <div class="section" id="sklearn-decomposition-latentdirichletallocation">
<h1><a class="reference internal" href="../classes.html#module-sklearn.decomposition" title="sklearn.decomposition"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sklearn.decomposition</span></code></a>.LatentDirichletAllocation<a class="headerlink" href="#sklearn-decomposition-latentdirichletallocation" title="Permalink to this headline">¶</a></h1>
<dl class="class">
<dt id="sklearn.decomposition.LatentDirichletAllocation">
<em class="property">class </em><code class="sig-prename descclassname">sklearn.decomposition.</code><code class="sig-name descname">LatentDirichletAllocation</code><span class="sig-paren">(</span><em class="sig-param">n_components=10</em>, <em class="sig-param">doc_topic_prior=None</em>, <em class="sig-param">topic_word_prior=None</em>, <em class="sig-param">learning_method='batch'</em>, <em class="sig-param">learning_decay=0.7</em>, <em class="sig-param">learning_offset=10.0</em>, <em class="sig-param">max_iter=10</em>, <em class="sig-param">batch_size=128</em>, <em class="sig-param">evaluate_every=-1</em>, <em class="sig-param">total_samples=1000000.0</em>, <em class="sig-param">perp_tol=0.1</em>, <em class="sig-param">mean_change_tol=0.001</em>, <em class="sig-param">max_doc_update_iter=100</em>, <em class="sig-param">n_jobs=None</em>, <em class="sig-param">verbose=0</em>, <em class="sig-param">random_state=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L135"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation" title="Permalink to this definition">¶</a></dt>
<dd><p>Latent Dirichlet Allocation with online variational Bayes algorithm</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 0.17.</span></p>
</div>
<p>Read more in the <a class="reference internal" href="../decomposition.html#latentdirichletallocation"><span class="std std-ref">User Guide</span></a>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl>
<dt><strong>n_components</strong><span class="classifier">int, optional (default=10)</span></dt><dd><p>Number of topics.</p>
</dd>
<dt><strong>doc_topic_prior</strong><span class="classifier">float, optional (default=None)</span></dt><dd><p>Prior of document topic distribution <code class="docutils literal notranslate"><span class="pre">theta</span></code>. If the value is None,
defaults to <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">/</span> <span class="pre">n_components</span></code>.
In <a class="reference internal" href="#re25e5648fc37-1" id="id1"><span>[Re25e5648fc37-1]</span></a>, this is called <code class="docutils literal notranslate"><span class="pre">alpha</span></code>.</p>
</dd>
<dt><strong>topic_word_prior</strong><span class="classifier">float, optional (default=None)</span></dt><dd><p>Prior of topic word distribution <code class="docutils literal notranslate"><span class="pre">beta</span></code>. If the value is None, defaults
to <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">/</span> <span class="pre">n_components</span></code>.
In <a class="reference internal" href="#re25e5648fc37-1" id="id2"><span>[Re25e5648fc37-1]</span></a>, this is called <code class="docutils literal notranslate"><span class="pre">eta</span></code>.</p>
</dd>
<dt><strong>learning_method</strong><span class="classifier">‘batch’ | ‘online’, default=’batch’</span></dt><dd><p>Method used to update <code class="docutils literal notranslate"><span class="pre">_component</span></code>. Only used in <a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.fit" title="sklearn.decomposition.LatentDirichletAllocation.fit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">fit</span></code></a> method.
In general, if the data size is large, the online update will be much
faster than the batch update.</p>
<p>Valid options:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>&#39;batch&#39;: Batch variational Bayes method. Use all training data in
    each EM update.
    Old `components_` will be overwritten in each iteration.
&#39;online&#39;: Online variational Bayes method. In each EM update, use
    mini-batch of training data to update the ``components_``
    variable incrementally. The learning rate is controlled by the
    ``learning_decay`` and the ``learning_offset`` parameters.
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 0.20: </span>The default learning method is now <code class="docutils literal notranslate"><span class="pre">&quot;batch&quot;</span></code>.</p>
</div>
</dd>
<dt><strong>learning_decay</strong><span class="classifier">float, optional (default=0.7)</span></dt><dd><p>It is a parameter that control learning rate in the online learning
method. The value should be set between (0.5, 1.0] to guarantee
asymptotic convergence. When the value is 0.0 and batch_size is
<code class="docutils literal notranslate"><span class="pre">n_samples</span></code>, the update method is same as batch learning. In the
literature, this is called kappa.</p>
</dd>
<dt><strong>learning_offset</strong><span class="classifier">float, optional (default=10.)</span></dt><dd><p>A (positive) parameter that downweights early iterations in online
learning.  It should be greater than 1.0. In the literature, this is
called tau_0.</p>
</dd>
<dt><strong>max_iter</strong><span class="classifier">integer, optional (default=10)</span></dt><dd><p>The maximum number of iterations.</p>
</dd>
<dt><strong>batch_size</strong><span class="classifier">int, optional (default=128)</span></dt><dd><p>Number of documents to use in each EM iteration. Only used in online
learning.</p>
</dd>
<dt><strong>evaluate_every</strong><span class="classifier">int, optional (default=0)</span></dt><dd><p>How often to evaluate perplexity. Only used in <code class="docutils literal notranslate"><span class="pre">fit</span></code> method.
set it to 0 or negative number to not evalute perplexity in
training at all. Evaluating perplexity can help you check convergence
in training process, but it will also increase total training time.
Evaluating perplexity in every iteration might increase training time
up to two-fold.</p>
</dd>
<dt><strong>total_samples</strong><span class="classifier">int, optional (default=1e6)</span></dt><dd><p>Total number of documents. Only used in the <a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.partial_fit" title="sklearn.decomposition.LatentDirichletAllocation.partial_fit"><code class="xref py py-meth docutils literal notranslate"><span class="pre">partial_fit</span></code></a> method.</p>
</dd>
<dt><strong>perp_tol</strong><span class="classifier">float, optional (default=1e-1)</span></dt><dd><p>Perplexity tolerance in batch learning. Only used when
<code class="docutils literal notranslate"><span class="pre">evaluate_every</span></code> is greater than 0.</p>
</dd>
<dt><strong>mean_change_tol</strong><span class="classifier">float, optional (default=1e-3)</span></dt><dd><p>Stopping tolerance for updating document topic distribution in E-step.</p>
</dd>
<dt><strong>max_doc_update_iter</strong><span class="classifier">int (default=100)</span></dt><dd><p>Max number of iterations for updating document topic distribution in
the E-step.</p>
</dd>
<dt><strong>n_jobs</strong><span class="classifier">int or None, optional (default=None)</span></dt><dd><p>The number of jobs to use in the E-step.
<code class="docutils literal notranslate"><span class="pre">None</span></code> means 1 unless in a <a class="reference external" href="https://joblib.readthedocs.io/en/latest/parallel.html#joblib.parallel_backend" title="(in joblib v0.14.1.dev0)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">joblib.parallel_backend</span></code></a> context.
<code class="docutils literal notranslate"><span class="pre">-1</span></code> means using all processors. See <a class="reference internal" href="../../glossary.html#term-n-jobs"><span class="xref std std-term">Glossary</span></a>
for more details.</p>
</dd>
<dt><strong>verbose</strong><span class="classifier">int, optional (default=0)</span></dt><dd><p>Verbosity level.</p>
</dd>
<dt><strong>random_state</strong><span class="classifier">int, RandomState instance or None, optional (default=None)</span></dt><dd><p>If int, random_state is the seed used by the random number generator;
If RandomState instance, random_state is the random number generator;
If None, the random number generator is the RandomState instance used
by <code class="docutils literal notranslate"><span class="pre">np.random</span></code>.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Attributes</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>components_</strong><span class="classifier">array, [n_components, n_features]</span></dt><dd><p>Variational parameters for topic word distribution. Since the complete
conditional for topic word distribution is a Dirichlet,
<code class="docutils literal notranslate"><span class="pre">components_[i,</span> <span class="pre">j]</span></code> can be viewed as pseudocount that represents the
number of times word <code class="docutils literal notranslate"><span class="pre">j</span></code> was assigned to topic <code class="docutils literal notranslate"><span class="pre">i</span></code>.
It can also be viewed as distribution over the words for each topic
after normalization:
<code class="docutils literal notranslate"><span class="pre">model.components_</span> <span class="pre">/</span> <span class="pre">model.components_.sum(axis=1)[:,</span> <span class="pre">np.newaxis]</span></code>.</p>
</dd>
<dt><strong>n_batch_iter_</strong><span class="classifier">int</span></dt><dd><p>Number of iterations of the EM step.</p>
</dd>
<dt><strong>n_iter_</strong><span class="classifier">int</span></dt><dd><p>Number of passes over the dataset.</p>
</dd>
<dt><strong>bound_</strong><span class="classifier">float</span></dt><dd><p>Final perplexity score on training set.</p>
</dd>
<dt><strong>doc_topic_prior_</strong><span class="classifier">float</span></dt><dd><p>Prior of document topic distribution <code class="docutils literal notranslate"><span class="pre">theta</span></code>. If the value is None,
it is <code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">/</span> <span class="pre">n_components</span></code>.</p>
</dd>
<dt><strong>topic_word_prior_</strong><span class="classifier">float</span></dt><dd><p>Prior of topic word distribution <code class="docutils literal notranslate"><span class="pre">beta</span></code>. If the value is None, it is
<code class="docutils literal notranslate"><span class="pre">1</span> <span class="pre">/</span> <span class="pre">n_components</span></code>.</p>
</dd>
</dl>
</dd>
</dl>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="re25e5648fc37-1"><span class="brackets">Re25e5648fc37-1</span><span class="fn-backref">(<a href="#id1">1</a>,<a href="#id2">2</a>)</span></dt>
<dd><p>“Online Learning for Latent Dirichlet Allocation”, Matthew D.
Hoffman, David M. Blei, Francis Bach, 2010</p>
</dd>
</dl>
<dl class="simple">
<dt>[2] “Stochastic Variational Inference”, Matthew D. Hoffman, David M. Blei,</dt><dd><p>Chong Wang, John Paisley, 2013</p>
</dd>
<dt>[3] Matthew D. Hoffman’s onlineldavb code. Link:</dt><dd><p><a class="reference external" href="https://github.com/blei-lab/onlineldavb">https://github.com/blei-lab/onlineldavb</a></p>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.decomposition</span> <span class="kn">import</span> <span class="n">LatentDirichletAllocation</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">make_multilabel_classification</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># This produces a feature matrix of token counts, similar to what</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># CountVectorizer would produce on text.</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">X</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">make_multilabel_classification</span><span class="p">(</span><span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lda</span> <span class="o">=</span> <span class="n">LatentDirichletAllocation</span><span class="p">(</span><span class="n">n_components</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
<span class="gp">... </span>    <span class="n">random_state</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lda</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
<span class="go">LatentDirichletAllocation(...)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="c1"># get topics for some given samples:</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">lda</span><span class="o">.</span><span class="n">transform</span><span class="p">(</span><span class="n">X</span><span class="p">[</span><span class="o">-</span><span class="mi">2</span><span class="p">:])</span>
<span class="go">array([[0.00360392, 0.25499205, 0.0036211 , 0.64236448, 0.09541846],</span>
<span class="go">       [0.15297572, 0.00362644, 0.44412786, 0.39568399, 0.003586  ]])</span>
</pre></div>
</div>
<p class="rubric">Methods</p>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.fit" title="sklearn.decomposition.LatentDirichletAllocation.fit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fit</span></code></a>(self, X[, y])</p></td>
<td><p>Learn model for the data X with variational Bayes method.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.fit_transform" title="sklearn.decomposition.LatentDirichletAllocation.fit_transform"><code class="xref py py-obj docutils literal notranslate"><span class="pre">fit_transform</span></code></a>(self, X[, y])</p></td>
<td><p>Fit to data, then transform it.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.get_params" title="sklearn.decomposition.LatentDirichletAllocation.get_params"><code class="xref py py-obj docutils literal notranslate"><span class="pre">get_params</span></code></a>(self[, deep])</p></td>
<td><p>Get parameters for this estimator.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.partial_fit" title="sklearn.decomposition.LatentDirichletAllocation.partial_fit"><code class="xref py py-obj docutils literal notranslate"><span class="pre">partial_fit</span></code></a>(self, X[, y])</p></td>
<td><p>Online VB with Mini-Batch update.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.perplexity" title="sklearn.decomposition.LatentDirichletAllocation.perplexity"><code class="xref py py-obj docutils literal notranslate"><span class="pre">perplexity</span></code></a>(self, X[, sub_sampling])</p></td>
<td><p>Calculate approximate perplexity for data X.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.score" title="sklearn.decomposition.LatentDirichletAllocation.score"><code class="xref py py-obj docutils literal notranslate"><span class="pre">score</span></code></a>(self, X[, y])</p></td>
<td><p>Calculate approximate log-likelihood as score.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.set_params" title="sklearn.decomposition.LatentDirichletAllocation.set_params"><code class="xref py py-obj docutils literal notranslate"><span class="pre">set_params</span></code></a>(self, \*\*params)</p></td>
<td><p>Set the parameters of this estimator.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="#sklearn.decomposition.LatentDirichletAllocation.transform" title="sklearn.decomposition.LatentDirichletAllocation.transform"><code class="xref py py-obj docutils literal notranslate"><span class="pre">transform</span></code></a>(self, X)</p></td>
<td><p>Transform data X according to the fitted model.</p></td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.__init__">
<code class="sig-name descname">__init__</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">n_components=10</em>, <em class="sig-param">doc_topic_prior=None</em>, <em class="sig-param">topic_word_prior=None</em>, <em class="sig-param">learning_method='batch'</em>, <em class="sig-param">learning_decay=0.7</em>, <em class="sig-param">learning_offset=10.0</em>, <em class="sig-param">max_iter=10</em>, <em class="sig-param">batch_size=128</em>, <em class="sig-param">evaluate_every=-1</em>, <em class="sig-param">total_samples=1000000.0</em>, <em class="sig-param">perp_tol=0.1</em>, <em class="sig-param">mean_change_tol=0.001</em>, <em class="sig-param">max_doc_update_iter=100</em>, <em class="sig-param">n_jobs=None</em>, <em class="sig-param">verbose=0</em>, <em class="sig-param">random_state=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L288"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.__init__" title="Permalink to this definition">¶</a></dt>
<dd><p>Initialize self.  See help(type(self)) for accurate signature.</p>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.fit">
<code class="sig-name descname">fit</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L527"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Learn model for the data X with variational Bayes method.</p>
<p>When <code class="docutils literal notranslate"><span class="pre">learning_method</span></code> is ‘online’, use mini-batch update.
Otherwise, use batch update.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">array-like or sparse matrix, shape=(n_samples, n_features)</span></dt><dd><p>Document word matrix.</p>
</dd>
<dt><strong>y</strong><span class="classifier">Ignored</span></dt><dd></dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt>self</dt><dd></dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.fit_transform">
<code class="sig-name descname">fit_transform</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em>, <em class="sig-param">y=None</em>, <em class="sig-param">**fit_params</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/base.py#L544"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.fit_transform" title="Permalink to this definition">¶</a></dt>
<dd><p>Fit to data, then transform it.</p>
<p>Fits transformer to X and y with optional parameters fit_params
and returns a transformed version of X.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">numpy array of shape [n_samples, n_features]</span></dt><dd><p>Training set.</p>
</dd>
<dt><strong>y</strong><span class="classifier">numpy array of shape [n_samples]</span></dt><dd><p>Target values.</p>
</dd>
<dt><strong>**fit_params</strong><span class="classifier">dict</span></dt><dd><p>Additional fit parameters.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>X_new</strong><span class="classifier">numpy array of shape [n_samples, n_features_new]</span></dt><dd><p>Transformed array.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.get_params">
<code class="sig-name descname">get_params</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">deep=True</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/base.py#L173"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.get_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Get parameters for this estimator.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>deep</strong><span class="classifier">bool, default=True</span></dt><dd><p>If True, will return the parameters for this estimator and
contained subobjects that are estimators.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>params</strong><span class="classifier">mapping of string to any</span></dt><dd><p>Parameter names mapped to their values.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.partial_fit">
<code class="sig-name descname">partial_fit</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L486"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.partial_fit" title="Permalink to this definition">¶</a></dt>
<dd><p>Online VB with Mini-Batch update.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">array-like or sparse matrix, shape=(n_samples, n_features)</span></dt><dd><p>Document word matrix.</p>
</dd>
<dt><strong>y</strong><span class="classifier">Ignored</span></dt><dd></dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt>self</dt><dd></dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.perplexity">
<code class="sig-name descname">perplexity</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em>, <em class="sig-param">sub_sampling=False</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L792"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.perplexity" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate approximate perplexity for data X.</p>
<p>Perplexity is defined as exp(-1. * log-likelihood per word)</p>
<div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 0.19: </span><em>doc_topic_distr</em> argument has been deprecated and is ignored
because user no longer has access to unnormalized distribution</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">array-like or sparse matrix, [n_samples, n_features]</span></dt><dd><p>Document word matrix.</p>
</dd>
<dt><strong>sub_sampling</strong><span class="classifier">bool</span></dt><dd><p>Do sub-sampling or not.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>score</strong><span class="classifier">float</span></dt><dd><p>Perplexity score.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.score">
<code class="sig-name descname">score</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em>, <em class="sig-param">y=None</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L723"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.score" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate approximate log-likelihood as score.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">array-like or sparse matrix, shape=(n_samples, n_features)</span></dt><dd><p>Document word matrix.</p>
</dd>
<dt><strong>y</strong><span class="classifier">Ignored</span></dt><dd></dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>score</strong><span class="classifier">float</span></dt><dd><p>Use approximate bound as score.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.set_params">
<code class="sig-name descname">set_params</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">**params</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/base.py#L205"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.set_params" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the parameters of this estimator.</p>
<p>The method works on simple estimators as well as on nested objects
(such as pipelines). The latter have parameters of the form
<code class="docutils literal notranslate"><span class="pre">&lt;component&gt;__&lt;parameter&gt;</span></code> so that it’s possible to update each
component of a nested object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>**params</strong><span class="classifier">dict</span></dt><dd><p>Estimator parameters.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>self</strong><span class="classifier">object</span></dt><dd><p>Estimator instance.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="sklearn.decomposition.LatentDirichletAllocation.transform">
<code class="sig-name descname">transform</code><span class="sig-paren">(</span><em class="sig-param">self</em>, <em class="sig-param">X</em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/scikit-learn/scikit-learn/blob/5f3c3f037/sklearn/decomposition/_online_lda.py#L627"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#sklearn.decomposition.LatentDirichletAllocation.transform" title="Permalink to this definition">¶</a></dt>
<dd><p>Transform data X according to the fitted model.</p>
<blockquote>
<div><div class="versionchanged">
<p><span class="versionmodified changed">Changed in version 0.18: </span><em>doc_topic_distr</em> is now normalized</p>
</div>
</div></blockquote>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>X</strong><span class="classifier">array-like or sparse matrix, shape=(n_samples, n_features)</span></dt><dd><p>Document word matrix.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl class="simple">
<dt><strong>doc_topic_distr</strong><span class="classifier">shape=(n_samples, n_components)</span></dt><dd><p>Document topic distribution for X.</p>
</dd>
</dl>
</dd>
</dl>
</dd></dl>

</dd></dl>

<div class="section" id="examples-using-sklearn-decomposition-latentdirichletallocation">
<h2>Examples using <code class="docutils literal notranslate"><span class="pre">sklearn.decomposition.LatentDirichletAllocation</span></code><a class="headerlink" href="#examples-using-sklearn-decomposition-latentdirichletallocation" title="Permalink to this headline">¶</a></h2>
<div class="sphx-glr-thumbcontainer" tooltip="This is an example of applying sklearn.decomposition.NMF and sklearn.decomposition.LatentDirich..."><div class="figure align-default" id="id4">
<img alt="../../_images/sphx_glr_plot_topics_extraction_with_nmf_lda_thumb.png" src="../../_images/sphx_glr_plot_topics_extraction_with_nmf_lda_thumb.png" />
<p class="caption"><span class="caption-text"><a class="reference internal" href="../../auto_examples/applications/plot_topics_extraction_with_nmf_lda.html#sphx-glr-auto-examples-applications-plot-topics-extraction-with-nmf-lda-py"><span class="std std-ref">Topic extraction with Non-negative Matrix Factorization and Latent Dirichlet Allocation</span></a></span><a class="headerlink" href="#id4" title="Permalink to this image">¶</a></p>
</div>
</div><div class="clearer"></div></div>
</div>


      </div>
    <div class="container">
      <footer class="sk-content-footer">
            &copy; 2007 - 2019, scikit-learn developers (BSD License).
          <a href="../../_sources/modules/generated/sklearn.decomposition.LatentDirichletAllocation.rst.txt" rel="nofollow">Show this page source</a>
      </footer>
    </div>
  </div>
</div>
<script src="../../_static/js/vendor/bootstrap.min.js"></script>

<script>
    window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
    ga('create', 'UA-22606712-2', 'auto');
    ga('set', 'anonymizeIp', true);
    ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>


<script>
$(document).ready(function() {
    /* Add a [>>>] button on the top-right corner of code samples to hide
     * the >>> and ... prompts and the output and thus make the code
     * copyable. */
    var div = $('.highlight-python .highlight,' +
                '.highlight-python3 .highlight,' +
                '.highlight-pycon .highlight,' +
		'.highlight-default .highlight')
    var pre = div.find('pre');

    // get the styles from the current theme
    pre.parent().parent().css('position', 'relative');
    var hide_text = 'Hide prompts and outputs';
    var show_text = 'Show prompts and outputs';

    // create and add the button to all the code blocks that contain >>>
    div.each(function(index) {
        var jthis = $(this);
        if (jthis.find('.gp').length > 0) {
            var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
            jthis.prepend(button);
        }
        // tracebacks (.gt) contain bare text elements that need to be
        // wrapped in a span to work with .nextUntil() (see later)
        jthis.find('pre:has(.gt)').contents().filter(function() {
            return ((this.nodeType == 3) && (this.data.trim().length > 0));
        }).wrap('<span>');
    });

    // define the behavior of the button when it's clicked
    $('.copybutton').click(function(e){
        e.preventDefault();
        var button = $(this);
        if (button.data('hidden') === 'false') {
            // hide the code output
            button.parent().find('.go, .gp, .gt').hide();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'hidden');
            button.css('text-decoration', 'line-through');
            button.attr('title', show_text);
            button.data('hidden', 'true');
        } else {
            // show the code output
            button.parent().find('.go, .gp, .gt').show();
            button.next('pre').find('.gt').nextUntil('.gp, .go').css('visibility', 'visible');
            button.css('text-decoration', 'none');
            button.attr('title', hide_text);
            button.data('hidden', 'false');
        }
    });

	/*** Add permalink buttons next to glossary terms ***/
	$('dl.glossary > dt[id]').append(function() {
		return ('<a class="headerlink" href="#' +
			    this.getAttribute('id') +
			    '" title="Permalink to this term">¶</a>');
	});
  /*** Hide navbar when scrolling down ***/
  // Returns true when headerlink target matches hash in url
  (function() {
    hashTargetOnTop = function() {
        var hash = window.location.hash;
        if ( hash.length < 2 ) { return false; }

        var target = document.getElementById( hash.slice(1) );
        if ( target === null ) { return false; }

        var top = target.getBoundingClientRect().top;
        return (top < 2) && (top > -2);
    };

    // Hide navbar on load if hash target is on top
    var navBar = document.getElementById("navbar");
    var navBarToggler = document.getElementById("sk-navbar-toggler");
    var navBarHeightHidden = "-" + navBar.getBoundingClientRect().height + "px";
    var $window = $(window);

    hideNavBar = function() {
        navBar.style.top = navBarHeightHidden;
    };

    showNavBar = function() {
        navBar.style.top = "0";
    }

    if (hashTargetOnTop()) {
        hideNavBar()
    }

    var prevScrollpos = window.pageYOffset;
    hideOnScroll = function(lastScrollTop) {
        if (($window.width() < 768) && (navBarToggler.getAttribute("aria-expanded") === 'true')) {
            return;
        }
        if (lastScrollTop > 2 && (prevScrollpos <= lastScrollTop) || hashTargetOnTop()){
            hideNavBar()
        } else {
            showNavBar()
        }
        prevScrollpos = lastScrollTop;
    };

    /*** high preformance scroll event listener***/
    var raf = window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        window.oRequestAnimationFrame;
    var lastScrollTop = $window.scrollTop();

    if (raf) {
        loop();
    }

    function loop() {
        var scrollTop = $window.scrollTop();
        if (lastScrollTop === scrollTop) {
            raf(loop);
            return;
        } else {
            lastScrollTop = scrollTop;
            hideOnScroll(lastScrollTop);
            raf(loop);
        }
    }
  })();
});

</script>
    
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
    
</body>
</html>